﻿using UnityEngine;
using System.Collections;

public class TestTextField : MonoBehaviour 
{
	private SaveGameManager.SaveData stringToEdit;

	private string lastString = "";
	private Rect m_ButtonRect;
	private Vector3 m_RectPosition;
	private bool m_IsInside;

	private void Start()
	{
		stringToEdit = new SaveGameManager.SaveData();
		stringToEdit.m_Value = SaveGameManager.Instance.GetValue(SaveDataID.AttributeID.STRING, SaveInfo.SaveDataType.STRING);
	}

	void OnGUI()
	{
		m_ButtonRect.width = Screen.width * 0.25f;
		m_ButtonRect.height = Screen.height * 0.15f;
		
		m_RectPosition.x = Screen.width/2f;
		m_RectPosition.y = Screen.height - 50f;
		m_ButtonRect.position = m_RectPosition;

		stringToEdit.m_Value = GUI.TextField(m_ButtonRect, (string)stringToEdit.m_Value, 25);
	}

	private void Update()
	{
		if(!m_IsInside && Input.GetMouseButton(0) && (string)stringToEdit.m_Value != lastString)
		{
			SaveGameManager.Instance.SetData(SaveDataID.AttributeID.STRING, stringToEdit);
			SaveGameManager.Instance.m_SaveTest.text = (string)stringToEdit.m_Value;
			
			lastString = (string)stringToEdit.m_Value;
		}
	}
}
